package com.itkjb.leisurely.resource.sys.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.itkjb.leisurely.resource.sys.model.SysUserDepModel;
import com.itkjb.leisurely.resource.sys.model.dto.SysUserDepDTO;
import com.itkjb.leisurely.resource.sys.model.vo.SysUserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户组织关系对象，组织成员 Mapper 接口
 * </p>
 *
 * @author itkjb.com
 * @since 2020-07-17
 */
public interface SysUserDepMapper extends BaseMapper<SysUserDepModel> {

    /**
     * 获取指定组织 可添加的用户列表
     * @param page
     * @param user
     * @return
     */
    IPage<SysUserVO> getNonMembers(IPage<?> page, @Param("user") SysUserDepDTO user);

    /**
     * 获取 指定组织  已添加的成员列表
     * @param page
     * @param user
     * @return
     */
    IPage<SysUserDepModel> getDepMembers(IPage<?> page,@Param("user") SysUserDepDTO user);

    /**
     * 查询用户的所有组织信息
     * @param userId
     * @return
     */
    @Select("select ud.* ,dep.dep_name as depName from sys_user_dep ud inner join sys_department dep on ud.dep_id = dep.id where " +
            "ud.user_id = #{userId} and dep.status = 1 and dep.is_del=0 and ud.status =1 and ud.is_del =0")
    List<SysUserDepModel> getUserDepsInfo(@Param("userId")String userId);

}
